/***
 * @description 商店与商品的数据操作
 * @author zhang
 */

const Shop = require('../models/Shop')
const Product = require('../models/Product')


/**
 * 获取商店列表
 * @returns list
 */
const shoplist = async () => {
    const list = await Shop.find().sort({ _id: -1 }) // 查找商铺列表

    return list
}


/**
 * 店铺详情
 * @param {String} id 
 * @returns shop
 */
const getshop = async id => {
    const shop = await Shop.findById(id)

    return shop
}


/**
 * 获取商店的商品列表
 * @param {String} id 
 * @returns productObj
 */
const getproduct = async (id, tabs = 'all') => { // 店铺id
    const productObj = await Product.find({
        shopId: id,
        tabs: {
            $in: tabs
        }
    })

    return productObj
}




module.exports = {
    shoplist,
    getshop,
    getproduct
}